//
// Created by TheHun on 2021/6/17.
//

#include "simMetaInfo.h"

SimMetaInfo* NewSimMetaInfo() {
    SimMetaInfo* meta = (SimMetaInfo*)malloc(sizeof(SimMetaInfo));
    return meta;
}

// 要求rawData中的第一列是时间序列信息
SimMetaInfo* loadMetaInfoFromRawData(RawData* rawData, double signalFreq) {
    if (rawData == NULL || rawData->data == NULL) {
        printf("rawData is NULL!\n");
        return NULL;
    }

    if (rawData->rowSize <= 1 || rawData->colSize <= 0) {
        printf("Illegal row/col size!\n");
        return NULL;
    }

    double startTime = rawData->data[0][0];
    double endTime = rawData->data[rawData->rowSize - 1][0];

    double totalTime = endTime - startTime;
    SimMetaInfo* meta = NewSimMetaInfo();
    meta->signalFreq = signalFreq;
    meta->totalTime = totalTime;
    meta->startTime = startTime;
    meta->signalLength = rawData->rowSize;
    meta->sampleFreq = totalTime / (rawData->rowSize - 1);
    meta->pointsPerCycle = (int)(meta->sampleFreq / meta->signalFreq);

    return meta;
}